﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WalutyNBP
{
    public partial class Ustawienia : Form
    {
        public Ustawienia()
        {
            InitializeComponent();
            checkBox3.Checked = Preferences.popularne;
            checkBox4.Checked = Preferences.popk;
            checkBox5.Checked = Preferences.popsp;
            checkBox1.Checked = Preferences.podstawowe;
            checkBox2.Checked = Preferences.pozostale;
            checkBox6.Checked = Preferences.rozliczeniowe;
            checkBox7.Checked = Preferences.rsr;
            checkBox8.Checked = Preferences.rs;
            checkBox9.Checked = Preferences.rk;
            checkBox10.Checked = Preferences.w_nazw_w;
            checkBox11.Checked = Preferences.w_nazw_w;
            checkBox12.Checked = Preferences.w_sym;
            checkBox13.Checked = Preferences.w_przel;
            Aktualne.Checked = Preferences.aktualne;
            checkBox14.Checked = Preferences.aktarch;
        }

        private void checkBox3_CheckStateChanged(object sender, EventArgs e)
        {
                Preferences.popularne = checkBox3.Checked;
                checkBox4.Enabled = checkBox3.Checked;
                checkBox5.Enabled = checkBox3.Checked;
                if (checkBox3.Checked)
                {
                    checkBox1.Enabled = false;
                    checkBox1.Checked = false;
                    checkBox2.Enabled = false;
                    checkBox2.Checked = false;
                    checkBox6.Enabled = false;
                    checkBox6.Checked = false;
                }
                else
                {
                    checkBox1.Enabled = true;
                    checkBox2.Enabled = true;
                    checkBox6.Enabled = true;
                }
        }

        private void checkBox4_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.popk = checkBox4.Checked;
        }

        private void checkBox5_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.popsp = checkBox5.Checked;
        }

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.podstawowe = checkBox1.Checked;
            if (checkBox1.Checked)
            {
                checkBox2.Enabled = false;
                checkBox2.Checked = false;
                checkBox3.Enabled = false;
                checkBox3.Checked = false;
                checkBox6.Enabled = false;
                checkBox6.Checked = false;
            }
            else
            {
                checkBox2.Enabled = true;
                checkBox3.Enabled = true;
                checkBox6.Enabled = true;
            }
        }

        private void checkBox2_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.pozostale = checkBox2.Checked;
            if (checkBox2.Checked)
            {
                checkBox1.Enabled = false;
                checkBox1.Checked = false;
                checkBox6.Enabled = false;
                checkBox6.Checked = false;
                checkBox3.Enabled = false;
                checkBox3.Checked = false;
            }
            else
            {
                checkBox1.Enabled = true;
                checkBox6.Enabled = true;
                checkBox3.Enabled = true;
            }
        }

        private void checkBox6_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.rozliczeniowe = checkBox6.Checked;
            checkBox7.Enabled = checkBox6.Checked;
            checkBox8.Enabled = checkBox6.Checked;
            checkBox9.Enabled = checkBox6.Checked;
            if (checkBox6.Checked)
            {
                checkBox1.Enabled = false;
                checkBox1.Checked = false;
                checkBox2.Enabled = false;
                checkBox2.Checked = false;
                checkBox3.Enabled = false;
                checkBox3.Checked = false;
            }
            else
            {
                checkBox1.Enabled = true;
                checkBox2.Enabled = true;
                checkBox3.Enabled = true;
            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            Preferences.dzien = dateTimePicker1.Value.Day.ToString();
            Preferences.miesiac = dateTimePicker1.Value.Month.ToString();
            Preferences.rok = dateTimePicker1.Value.Year.ToString();
            Preferences.full_date = dateTimePicker1.Value.Date;
        }

        private void checkBox9_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.rk = checkBox9.Checked;
        }

        private void checkBox8_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.rs = checkBox8.Checked;
        }

        private void checkBox7_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.rsr = checkBox7.Checked;
        }

        private void checkBox10_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.w_nazw_w = checkBox10.Checked;
            if (checkBox10.Checked == false)
            {
                checkBox12.Checked = true;
                checkBox12.Enabled = false;
            }
            else
            {
                checkBox12.Enabled = true;
            }
        }

        private void checkBox11_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.w_nazw_k = checkBox11.Checked;
        }

        private void checkBox12_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.w_sym = checkBox12.Checked;
            if (checkBox12.Checked)
            {
                checkBox13.Enabled = true;
            }
            else
            {
                checkBox13.Enabled = false;
                checkBox13.Checked = false;
            }
        }

        private void checkBox13_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.w_przel = checkBox13.Checked;
            
        }

        private void Aktualne_CheckStateChanged(object sender, EventArgs e)
        {
            dateTimePicker1.Enabled = !Aktualne.Checked;
            checkBox14.Enabled = !Aktualne.Checked;
            Preferences.aktualne = Aktualne.Checked;
        }

        private void Ustawienia_Closing(object sender, CancelEventArgs e)
        {
            Preferences.dzien = dateTimePicker1.Value.Day.ToString();
            Preferences.miesiac = dateTimePicker1.Value.Month.ToString();
            Preferences.rok = dateTimePicker1.Value.Year.ToString();
            Preferences.full_date = dateTimePicker1.Value.Date;
            if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked && !checkBox6.Checked)
            {
                MessageBox.Show("Musisz wybrać jedną opcję główną");
                checkBox1.Checked = true;
            }
            if (checkBox3.Checked && !checkBox4.Checked && !checkBox5.Checked)
            {
                MessageBox.Show("Musisz wybrać co najmniej jedną opcję");
                checkBox4.Checked = true;
            }
            if (checkBox6.Checked && !checkBox7.Checked && !checkBox8.Checked && !checkBox9.Checked)
            {
                MessageBox.Show("Musisz wybrać co najmniej jedną opcję");
                checkBox7.Checked = true;
            }
        }

        private void checkBox14_CheckStateChanged(object sender, EventArgs e)
        {
            Preferences.aktarch = checkBox14.Checked;
        }
    }
}